package com.example.ticket.demo.ticket;

import com.example.ticket.demo.model.table.Ticket;
import com.example.ticket.demo.service.ITicketService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


/**
 * 售票员控制台
 * 
 * @author liu.nh
 *
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class TicketSalerConsole {
	
	@Autowired
	private ITicketService ticketService;

	@Test
	public void testBbb() {
		Ticket record = ticketService.selectByPrimaryKey("1");
		record.setId(record.getId());
		record.setTicketCount(200);
		ticketService.updateByPrimaryKeySelective(record);
	}
	
	@Test
	public void testAaa() throws InterruptedException {
		for(int i = 0; i < 55; i++){
			ticketSaler1();
			ticketSaler2();
			ticketSaler3();
			ticketSaler4();
		}
	}
	
	private void ticketSaler1() throws InterruptedException {
		TicketSaleThread s1 = new TicketSaleThread("S1");
		Thread t1 = new Thread(s1);
		t1.setName("T1");
		t1.start();
		t1.join();
	}
	
    private void ticketSaler2() throws InterruptedException {
		TicketSaleThread s2 = new TicketSaleThread("S2");
		Thread t2 = new Thread(s2);
		t2.setName("T2");
		t2.start();
		t2.join();
	}

	private void ticketSaler3() throws InterruptedException {
		TicketSaleThread s3 = new TicketSaleThread("S3");
		Thread t3 = new Thread(s3);
		t3.setName("T3");
		t3.start();
		t3.join();
	}
	
	private void ticketSaler4() throws InterruptedException {
		TicketSaleThread s4 = new TicketSaleThread("S4");
		Thread t4 = new Thread(s4);
		t4.setName("T4");
		t4.start();
		t4.join();
	}

}
